package c1761;

import java.util.Collections;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Vector;

public class B {
    static class Score implements Comparable<Score> {
        int ac;
        int time;
        String name;

        @Override
        public int compareTo(Score o) {
            if (this.ac != o.ac) return o.ac - this.ac;//从大到小
            if (this.time != o.time) return this.time - o.time;
            return this.name.compareTo(o.name);//从小到大

        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        Vector<Score> v = new Vector<Score>();
        int i = 0;
        while (scan.hasNext()) {
            Score cur = new Score();
            cur.name = scan.next();
            for (int j = 0; j < n; j++) {
                String s = scan.next();
                if (s.charAt(0) == '0') continue;
                else if (s.charAt(0) == '-') continue;
                else if (s.charAt(0) > '0' && s.charAt(0) <= '9') {
                    cur.ac++;
                    if (s.indexOf('(') < 0) {
                        cur.time += Integer.parseInt(s);
                    } else {
                        String ls = s.substring(0, s.indexOf('('));
                        cur.time += Integer.parseInt(ls);
                        String rs = s.substring(s.indexOf('(') + 1, s.indexOf(')'));
                        cur.time += m * Integer.parseInt(rs);
                    }
                }
            }
            v.add(cur);
        }
        Collections.sort(v);
        for (Score s : v) {//wrong在i
            System.out.printf("%-10s%3d%5d", s.name, s.ac, s.time);
            System.out.println();
        }
    }
}
